home *** CD-ROM | disk | FTP | other *** search
- (***************************************************************************
-
- $RCSfile: HalveFile.mod $
- Description: A quick hack to halve a file too big to edit
-
- Created by: fjc (Frank Copeland)
- $Revision: 1.4 $
- $Author: fjc $
- $Date: 1995/01/26 01:05:15 $
-
- Copyright © 1994, Frank Copeland.
- This file is part of Oberon-A.
- See Oberon-A.doc for conditions of use and distribution.
-
- Log entries are at the end of the file.
-
- ***************************************************************************)
-
- <*STANDARD-*>
-
- MODULE HalveFile;
-
- IMPORT SYS := SYSTEM, F := Files, Str := Strings, IO := StdIO, Args;
-
- TYPE
- Path = ARRAY 256 OF CHAR;
-
- VAR
- fileName, firstHalf, secondHalf : Path;
-
- (*------------------------------------*)
- PROCEDURE GetArgs ();
-
- BEGIN (* GetArgs *)
- IF Args.argc = 2 THEN
- COPY (Args.argv [1]^, fileName);
- COPY (fileName, firstHalf);
- Str.Append ("_1", firstHalf);
- COPY (fileName, secondHalf);
- Str.Append ("_2", secondHalf);
- IO.WriteF3
- ( "Copying %s to %s & %s\n",
- SYS.ADR (fileName), SYS.ADR (firstHalf), SYS.ADR (secondHalf) )
- ELSE
- IO.WriteStr ("Usage : HalveFile <file>\n");
- HALT (20)
- END; (* ELSE *)
- END GetArgs;
-
- (*------------------------------------*)
- PROCEDURE CopyFile ();
-
- VAR
- f, f1, f2 : F.File;
- r, w : F.Rider;
- len, count, bytes : LONGINT;
- buf : POINTER TO ARRAY 1024 OF SYS.BYTE;
-
- BEGIN (* CopyFile *)
- NEW (buf);
- f := F.Old (fileName);
- IF f # NIL THEN
- len := F.Length (f);
- f1 := F.New (firstHalf);
- IF f1 # NIL THEN
- F.Set (r, f, 0);
- F.Set (w, f1, 0);
- count := len DIV 2;
- WHILE count > 0 DO
- IF count > 1024 THEN bytes := 1024
- ELSE bytes := count
- END;
- F.ReadBytes (r, buf^, bytes);
- F.WriteBytes (w, buf^, bytes);
- DEC (count, bytes)
- END; (* WHILE *)
- F.Register (f1);
- f2 := F.New (secondHalf);
- IF f2 # NIL THEN
- F.Set (w, f2, 0);
- count := len - (len DIV 2);
- WHILE count > 0 DO
- IF count > 1024 THEN bytes := 1024
- ELSE bytes := count
- END;
- F.ReadBytes (r, buf^, bytes);
- F.WriteBytes (w, buf^, bytes);
- DEC (count, bytes)
- END; (* WHILE *)
- F.Register (f2)
- ELSE
- IO.WriteF1 ("Could not open %s\n", SYS.ADR (secondHalf))
- END; (* ELSE *)
- ELSE
- IO.WriteF1 ("Could not open %s\n", SYS.ADR (firstHalf))
- END; (* ELSE *)
- F.Close (f)
- ELSE
- IO.WriteF1 ("Could not open %s\n", SYS.ADR (fileName))
- END; (* ELSE *)
- END CopyFile;
-
- BEGIN (* HalveFile *)
- IO.WriteStr ("HalveFile\n");
- IO.WriteStr ("Written by Frank Copeland\n\n");
- GetArgs ();
- CopyFile ()
- END HalveFile.
-
- (***************************************************************************
-
- $Log: HalveFile.mod $
- Revision 1.4 1995/01/26 01:05:15 fjc
- - Release 1.5
-
- Revision 1.3 1994/09/25 18:25:17 fjc
- - Uses new syntax for external code declarations
-
- Revision 1.2 1994/08/08 16:28:05 fjc
- Release 1.4
-
- Revision 1.1 1994/05/12 20:20:07 fjc
- - Prepared for release
-
- Revision 1.0 1994/01/16 13:54:25 fjc
- Start of version control
-
-
- ***************************************************************************)
-
-
-